<template>
  <div>
    <h1>登录页面</h1>

    <table>
      <tr>
        <td>账号</td>
        <td>
          <input type="text" v-model="loginInfo.UserName" >
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="loginInfo.UserPwd" >
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="登录" @click="login" >
        </td>
      </tr>
    </table>

  </div>
</template>

<script setup lang="ts">
    import router from '@/router';
import axios from 'axios';
    import {reactive,toRefs} from 'vue'

    let data:any=reactive({
      loginInfo:{
        UserName:'',
        UserPwd:''
      }
    })

    let {loginInfo} =toRefs(data);
    
    
    const login=()=>{
      axios({
        url:'/api/User/Login',
        method:'get',
        params:loginInfo.value
      }).then(res=>{
        if (res.data==-1) {
          alert('用户名不存在');
        }else  if (res.data==-2) {
          alert('密码错误');
        }
        else  if (res.data!=null) {
          alert('登录成功');
          router.push('/show');
        }else
        {
          alert('登录失败');

        }

      }).catch(err=>{

      })
    }

    
</script>

<style scoped>

</style>